package com.springdoor.web.controller.goods;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.springdoor.goods.domain.SprdGoodsMain;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.springdoor.common.annotation.Log;
import com.springdoor.common.core.controller.BaseController;
import com.springdoor.common.core.domain.AjaxResult;
import com.springdoor.common.enums.BusinessType;
import com.springdoor.goods.domain.SprdGoodsConfig;
import com.springdoor.goods.service.ISprdGoodsConfigService;
import com.springdoor.common.utils.poi.ExcelUtil;

/**
 * 商品参数信息Controller
 * 
 * @author llshs
 * @date 2024-04-30
 */
@RestController
@RequestMapping("/goods/config")
public class SprdGoodsConfigController extends BaseController
{
    @Autowired
    private ISprdGoodsConfigService configService;

    /**
     * 查询商品参数信息列表
     */
    @PreAuthorize("@ss.hasPermi('goods:config:list')")
    @GetMapping("/list")
    public AjaxResult list(SprdGoodsConfig sprdGoodsConfig)
    {
        /*startPage();
        List<SprdGoodsConfig> list = sprdGoodsConfigService.selectSprdGoodsConfigList(sprdGoodsConfig);
        return getDataTable(list);*/
        return success(configService.selectSprdGoodsConfigList(sprdGoodsConfig));
    }

    /**
     * 导出商品参数信息列表
     */
    @PreAuthorize("@ss.hasPermi('goods:config:export')")
    @Log(title = "商品参数信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SprdGoodsConfig sprdGoodsConfig)
    {
        List<SprdGoodsConfig> list = configService.selectSprdGoodsConfigList(sprdGoodsConfig);
        ExcelUtil<SprdGoodsConfig> util = new ExcelUtil<SprdGoodsConfig>(SprdGoodsConfig.class);
        util.exportExcel(response, list, "商品参数信息数据");
    }

    /**
     * 获取商品参数信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:config:query')")
    @GetMapping(value = "/{gConfigId}")
    public AjaxResult getInfo(@PathVariable("gConfigId") Long gConfigId)
    {
        return success(configService.selectSprdGoodsConfigByGConfigId(gConfigId));
    }

    /**
     * 新增商品参数信息
     */
    @PreAuthorize("@ss.hasPermi('goods:config:add')")
    @Log(title = "商品参数信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SprdGoodsMain sprdGoodsMain)
    {
        if (sprdGoodsMain == null || StringUtils.isEmpty(sprdGoodsMain.getgNumber())) {
            return error("参数错误");
        }
        sprdGoodsMain.setUpdateBy(getUsername());
        return toAjax(configService.insertSprdGoodsConfig(sprdGoodsMain));
    }

    /**
     * 查询商品参数信息列表
     */
    @PreAuthorize("@ss.hasAnyPermi('goods:config:edit,goods:config:add')")
    @GetMapping("/getAssConfig/{assNumber}")
    public AjaxResult getAssConfig(@PathVariable("assNumber") String assNumber)
    {
        if (StringUtils.isNotBlank(assNumber)) {
            SprdGoodsConfig config = new SprdGoodsConfig();
            config.setgNumber(assNumber);
            config.setDelFlag("0");
            return success(configService.selectSprdGoodsConfigList(config));
        }
        return success(null);
    }
}
